// export {}

import { IServiceAgentRequest, ServiceAgent } from 'grey-service-agent'
import UserInfo from 'central/UserInfo';
import { Toast } from 'antd-mobile';

export const server = new ServiceAgent('/medicine-server');

server.reqFs = [
    (req: IServiceAgentRequest): IServiceAgentRequest => {
        req.sar.set({ Authorization: UserInfo.instance.state.token });
        req.sar.set({ 'Content-Type': 'application/json' });
        return req;
    }
]

server.resFs = [
    value => {
        if (value.res.status !== 200) {
            Toast.fail(value.res.text);
            return {
                ...value,
                err: value.res
            }
        }

        if (value.res.body.status.errorCode !== '00000') {
            Toast.fail(value.res.body.status.errorMsg);
            return {
                ...value,
                err: value.res
            }
        }

        return value;
    }
]